<?php

/*
 * Action 3$
 *
 * +1 Action
 * +1 Buy
 * Trash a card from your hand. +1 Coin per differently named Treasure card in the trash.
 */

class Forager extends Card implements iAction, iKingdom, iDarkAges {

    public function __construct() {
        parent::__construct("Forager", 3);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+1 Action",
            "+1 Buy",
            "Trash a card from your hand. +1 Coin per differently named Treasure card in the trash.");
    }

    public function play(Game $game, $isRealCard) {
        $game->addActions(1);
        $game->addBuys(1);
        ScreenDisplay::addScreenMessage($game, true, "get +1 action and +1 buy ", "gets +1 action and +1 buy");

        $playhand = $game->getPlayHand();
        if (sizeof($playhand) > 0) {
            $playhand = getUniqueCards($playhand);
            if (sizeof($playhand) > 1) {
                $output = MySocket::GetUserReply($game, Input_ChooseOne, $playhand, 1, 1, null, "Choose card to trash");
                $old_card_name = $output[0];
            }
            else {
                $old_card_name = $playhand[0];
            }
            $old_card = $game->moveCardFromPileToPile($old_card_name, PlayHand, Trash);
            ScreenDisplay::addScreenMessage($game, false, ", trash " . nicePrint($old_card), ", trashes " . ScreenDisplay::$LMSG);
        }
        $trash = $game->getTrash();
        $treasures = array();
        foreach ($trash as $card) {
            if ($card instanceof iTreasure) {
                $treasures[] = $card;
            }
        }

        $unique = getUniqueCards($treasures);
        $coins = sizeof($unique);
        $game->addMoney(new Price($coins));
        ScreenDisplay::addScreenMessage($game, false, " and get +$coins$", " and gets +$coins$");
        $game->cardActionFinished();
        return true;
    }

}

?>